function WeiYingXiao_Code()
{
	var buffer = new StringBuffer();
	buffer.append('<div class="weitab"><div class="cusline1 select1" val="1">粘贴链接</div><div class="cusline2" val="2">我的推广</div><div class="cusline3" val="3">我的广告</div></div>');
	buffer.append('<div class="weipanel border-top"></div>');
	buffer.append('<div class="weipanel1"><textarea id="txt_link" placeholder="请粘贴或输入文章链接"></textarea><div id="clear" class="clear">清空</div><button id="share">分享</button></div>');
	buffer.append('<div class="tips">让您的广告疯一样的出现在朋友圈 &nbsp;<a id="example">示例</a></div>');
	buffer.append('<div id="weipanel10" pageindex="0" class="weipanel2 hidden" style="height:'+(sheight-66)+'px;"><div id="wrapper10"><div id="scroller"><div id="reflash10"></div><div id="info10" style="padding-top:25px;"></div><div id="loading10"><img src="img/loading.gif"/></div></div></div></div>');
	buffer.append('<div class="weipanel3 hidden"><div class="weiname">顶部广告</div><div id="topad" class="weiad"><img id="0" src="img/yimiao.gif" oldsrc=""/></div><div class="weilink"><input type="text" placeholder="输入广告链接" value=""/></div></div>');
	buffer.append('<div class="weipanel3 hidden border-top" style="padding-top:30px;"><div class="weiname">底部广告</div><div id="bottomad" class="weiad"><img id="0" src="img/yimiao.gif" oldsrc=""/></div><div class="weilink"><input type="text" placeholder="输入广告链接" value=""/></div><div class="save"><button id="savead">保存</button></div></div>');
	return buffer.toString();
};

function Init_WeiYingXiao()
{
	//updateSerivces();
	
	mui(".weitab").on("tap","div",function(){
			$(".weitab .cusline1").removeClass("select1");
			$(".weitab .cusline2").removeClass("select2");
			$(".weitab .cusline3").removeClass("select3");
			$(this).addClass("select"+$(this).attr("val"));
			//$("#panel1"+ (parseInt($(this).attr("val"))-1)).removeClass("hidden").siblings().addClass("hidden");
			if($(this).attr("val")=="1")
			{
				$(".weipanel1,.tips").removeClass("hidden");
				$(".weipanel2,.weipanel3").addClass("hidden");
			}
			if($(this).attr("val")=="2")
			{
				$(".weipanel2").removeClass("hidden");
				$(".weipanel1,.weipanel3,.tips").addClass("hidden");
				pageindex = 1;
         		$("#weipanel10").attr("pageindex",0);
         		if($("#weipanel10 .weilist").length==0){
					myScroll10=AtScroll(10,"weipanel10",function(pageindex){
						Receive_UserNews(pageindex);
					});
					Receive_UserNews(1);
				}
			}
			if($(this).attr("val")=="3")
			{
				$(".weipanel3").removeClass("hidden");
				$(".weipanel1,.weipanel2,.tips").addClass("hidden");
				//初始化广告
				var data = {};
					data.act = "FindMyAds";
					data.source=source;
					data.userid=userid;
					data.comid=comid;
					data.sign=GetSign(data.act);
					mui.getJSON(index_domain, data, function (json) {
				            if (json.state) {
				            	var ads = json.data;
				            	if(ads.length==2)
				            	{
				            		$("#topad img").attr("src",ads[0].Img).attr("oldsrc",ads[0].Img).attr("id",ads[0].ID);
				            		$("#topad").parent().find("input").val(ads[0].Link);
				            		$("#bottomad img").attr("src",ads[1].Img).attr("oldsrc",ads[1].Img).attr("id",ads[1].ID);
				            		$("#bottomad").parent().find("input").val(ads[1].Link);
				            		
				            	}
				            } else {
								plus.nativeUI.toast(json.msg);
				            } 
				});
			}
	});
	get("clear").addEventListener("tap",function(){
		$("#txt_link").val("");
	});
	get("example").addEventListener("tap",function(){
		OpenWindow(4,"示例","",function(){
			
		});
		$("#contentlist4").html("<img src='img/xiao.png' style='width:100%; height:100%'/>");
	});
	get("share").addEventListener("tap",function(){
		var data = {};
		data.act = "LinkToNews";
		data.source=source;
		data.userid=userid;
		data.comid=comid;
		data.link=$("#txt_link").val();
		if(data.link.Trim()=="")
		{
			plus.nativeUI.toast("请粘贴或输入文章链接");
			return;
		}
		data.sign=GetSign(data.act);
		var wt=plus.nativeUI.showWaiting("正在生成文章...");
		mui.getJSON(index_domain, data, function (json) {
				wt.close();
	            if (json.state) {
	            	$("#txt_link").val("");
	            	OpenWindow(3,"分享","",function(){
					});
					$("#contentlist3").html("<iframe src='"+json.data.newslink+"' width='100%' height='100%' frameborder='0'></iframe>");
					$("#divmsg3").append("<div style='width:100%; height:80px; position:absolute; bottom:0px; z-index:9999; background-color:#fff;'><div class='share'>朋友圈</div><div class='share'>微信好友</div><div class='share'>新浪微博</div><div class='share'>腾讯微博</div></div>");
	            } else {
					plus.nativeUI.toast(json.msg);
	            } 
	    });
	});
	get("topad").addEventListener("tap",function(){
		plus.gallery.pick(function(path) {
			$("#topad img").attr("src",path);
		}, function(err) {}, {filter:"image",multiple:false});
	});
	get("bottomad").addEventListener("tap",function(){
		plus.gallery.pick(function(path) {
			$("#bottomad img").attr("src",path);
		}, function(err) {}, {filter:"image",multiple:false});
	});
	get("savead").addEventListener("tap",function(){
		var wt=plus.nativeUI.showWaiting("正在保存...");
		var upload_count=0,hasupload_count=0;
		var hasupload_link=false;
		var topimg=$("#topad img");
		var bottomimg=$("#bottomad img");
		if(topimg.attr("src")!=topimg.attr("oldsrc"))
		{
			upload_count++;
		}
		if(bottomimg.attr("src")!=bottomimg.attr("oldsrc"))
		{
			upload_count++;
		}
		var datas = {};
		datas.act = "Save_WAdLink";
		datas.id1=topimg.attr("id");
		datas.id2=bottomimg.attr("id");
		datas.source=source;
		datas.userid=userid;
		datas.comid=comid;

		datas.link1=topimg.parent().parent().find("input").val();
		datas.link2=bottomimg.parent().parent().find("input").val();
		data.sign=GetSign(data.act);
		mui.getJSON(index_domain, datas, function (json) {
			hasupload_link=true;
			if(upload_count==hasupload_count)
			{
				wt.close();
				plus.nativeUI.toast(json.msg);
			}
		});
		if(topimg.attr("src")!=topimg.attr("oldsrc"))
		{
			upload5(topimg.attr("src"),function(img){
				data = {};
					data.act = "Save_WAd";
					data.id=topimg.attr("id");
					data.source=source;
					data.userid=userid;
					data.comid=comid;
					data.img=eval(img).join(",");
					data.old_img=topimg.attr("oldsrc");
					data.sign=GetSign(data.act);
					mui.getJSON(index_domain, data, function (json) {
				        hasupload_count++;
				        if(upload_count==hasupload_count && hasupload_link)
				        {
				        	wt.close();
				        	plus.nativeUI.toast(json.msg);
				        }
					});
			});
		}
		if(bottomimg.attr("src")!=bottomimg.attr("oldsrc"))
		{
			upload5(bottomimg.attr("src"),function(img){
				data = {};
					data.act = "Save_WAd";
					data.id=bottomimg.attr("id");
					data.source=source;
					data.userid=userid;
					data.comid=comid;
					data.img=eval(img).join(",");
					data.old_img=bottomimg.attr("oldsrc");
					data.sign=GetSign(data.act);
					mui.getJSON(index_domain, data, function (json) {
				        hasupload_count++;
				        if(upload_count==hasupload_count && hasupload_link)
				        {
				        	wt.close();
				        	plus.nativeUI.toast(json.msg);
				        }
					});
			});
		}
	});
};

function UserNews_Data(data){
	var buffer = new StringBuffer();
	$(data).each(function(i,info){
		buffer.append('<div class="weilist border-bottom" id="'+info.ID+'"><div class="weiimg"><img src="'+info.Img+'" /></div><div class="weicontext"><div class="weititle">'+info.Title+'</div><div class="weibottom"><div class="click">浏览量：'+info.Click+'</div><div class="createdate">'+info.CreateDate.ToTime()+'</div></div></div></div>');
	});
	return buffer.toString();
};

function Receive_UserNews(pageindex)
{
	var data = {};
			data.act = "FindMyNews";
			data.userid=userid;
			data.comid=comid;
			data.pageindex=pageindex;
			data.source=source;
			data.pagesize=PAGE_SIZE20;
			data.sign=GetSign(data.act);
			
			mui.getJSON(index_domain, data, function(json) {
				if(json.data.length>0)
				{
					if(pageindex==1)
					{
						$("#info10").html(UserNews_Data(json.data));
					}else{
						$("#info10").append(UserNews_Data(json.data));
					}
					if(json.data.length!=data.pagesize)
					{
						$("#loading10").html("");
					}else{
						$("#loading10").html('<img src="img/loading.gif"/>');
					}
					setTimeout(function(){
						//Init_NotePad();
						myScroll10.refresh();
					},500); //需要延迟500毫秒加载，否则当数量少时不能下拉
					
				}else
				{
					if(pageindex==1)
					{
						$("#loading10").html("主人，没有找到您需要的数据");
					}else
					{
						$("#loading10").html("没有更多了");
					}
				}
				
         		pageindex = parseInt($("#weipanel10").attr("pageindex"))+1;
         		$("#weipanel10").attr("pageindex",pageindex);
			});
};

var shares=null,bhref=false;
function updateSerivces(){
	plus.share.getServices( function(s){
		shares={};
		for(var i in s){
			var t=s[i];
			shares[t.id]=t;
		}
	}, function(e){
		outSet( "获取分享服务列表失败："+e.message );
	} );
};


function upload5(src,fun){

				var task=plus.uploader.createUpload(upload_domain,
					{method:"POST"},
					function(t,status){ //上传完成
						if(status==200){
							fun(t.responseText);
						}else{
						}
					}
				);
				var date = new Date();
				task.addData("userid",userid);
				task.addData("comid",comid);
				task.addData("handle","upload_ad");
				task.addData("random",date.Format("hhmmss"));
				task.addFile(src,{key:src});
				task.start();
			
      		
	};